package com.gjp.config;

import com.baomidou.mybatisplus.entity.GlobalConfiguration;
import com.baomidou.mybatisplus.enums.DBType;
import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by gjp on 2017-6-2.
 */
@Configuration
@MapperScan("com.gjp.mapper*")
public class MybatisPlusConfig {

    @Bean
    public GlobalConfiguration globalConfiguration() {
        GlobalConfiguration globalConfiguration = new GlobalConfiguration();
       /* 主键策略配置
        可选参数
        AUTO->`0`("数据库ID自增")
        INPUT->`1`(用户输入ID")
        ID_WORKER->`2`("全局唯一ID")
        UUID->`3`("全局唯一ID")*/
        globalConfiguration.setIdType(0);
       /* 数据库类型配置
        可选参数（默认mysql）
        MYSQL ->`mysql`
        ORACLE ->`oracle`
        DB2 ->`db2`
        H2 ->`h2`
        HSQL ->`hsql`
        SQLITE ->`sqlite`
        POSTGRE ->`postgresql`
        SQLSERVER2005 ->`sqlserver2005`
        SQLSERVER ->`sqlserver`*/
        //globalConfiguration.setDbType();
        return globalConfiguration;
    }


    /**
     * mybatis-plus分页插件<br>
     * 文档：http://mp.baomidou.com<br>
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        paginationInterceptor.setDialectType(DBType.MYSQL.getDb());
        return paginationInterceptor;
    }
}
